from selenium.webdriver.common.by import By

from common.Utils import BlogDriver


class BlogPostEditingTest:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    def PostEditingEleTest(self):
        #板块选项框是否可以选择
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad > option:nth-child(2)").click()
        BlogDriver.getScreeShot()

        #标题选项框是否可以输入
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("haha")
        BlogDriver.getScreeShot()

        #内容编辑组件是否正常使用
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(7) > a > i").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        BlogDriver.getScreeShot()

    def PostEditingSucSendTest(self):
        #有选项 & 有标题 & 编辑内容
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_borad > option:nth-child(2)").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("测试")
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(7) > a > i").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        BlogDriver.getScreeShot()


    def PostEditingFailSendTest(self):
        #有标题 & 无编辑内容
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("测试")
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        BlogDriver.getScreeShot()

        #无标题&编辑内容
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.editormd-toolbar > div > ul > li:nth-child(7) > a > i").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        BlogDriver.getScreeShot()

        #无标题&无编辑内容
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        BlogDriver.getScreeShot()
